<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %><%--
  Created by IntelliJ IDEA.
  User: 电脑
  Date: 2024/10/25
  Time: 11:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String username ="root";
    String pwd="990106";
    String url="jdbc:mysql://localhost:3306/text?serverTimezone=Asia/Shanghai";
    //1连接数据库的驱动
    Class.forName("com.mysql.cj.jdbc.Driver");
    // 2利用驱动管理连接数据库 获取连接对象connection
    Connection conn = DriverManager.getConnection(url, username, pwd);
    //3利用连接对象获取statement 对象 MySQL。exe
    Statement statement = conn.createStatement();
//    4sqql
    String sql="select *from student ";
//    查寻返回结果集
    ResultSet rs=statement.executeQuery(sql);

//    select查询  update delete insert(更新)
//    statment excuteUpdate()
//    System.out.println(resultSet);
//    while(resultSet.next()) {
//    String number = resultSet.getString("number");
//    String name = resultSet.getString("name");
//    String birthday = resultSet.getString("birthday");
//    String styles = resultSet.getString("stuclass");
//    System.out.println(number);
//    System.out.println(birthday);
//    System.out.println(styles);
//    System.out.println(name);
//}
%>

    <table border="1">
    <th colopan="4" style="font-size:x-large;alignment:center">学生信息表</th>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>班级</td>
    </tr>
        <% while (rs.next()){%>
        <tr style="text-align: center">
            <td><%=rs.getString(1)%></td>
            <td><%=rs.getString(2)%></td>
            <td><%=rs.getString("birthday")%></td>
            <td><%=rs.getString("stuclass")%></td>
        </tr>
        <%}%>
        <%
            rs.close();
            statement.close();
            conn.close();

        %>
    </table>
</body>
</html>